<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("components4phpfull/jtdatepicker.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class Set_Reminder_Edit extends Page
{
       public $dpDue2 = null;
       public $edDue = null;
       public $lblhr = null;
       public $lblHours = null;
       public $lblDueat = null;
       public $lblDueby = null;
       public $JTDivType = null;
       public $JTGroupBox1 = null;
       public $btnAddType = null;
       public $btnDelType = null;
       public $edType = null;
       public $listType = null;
       public $imgBack = null;
       public $dpDue1 = null;
       public $hfsched = null;
       public $btnCancel = null;
       public $btnUpdate = null;
       public $btnShowType = null;
       public $JTJavaScript3 = null;
       public $JTJavaScript2 = null;
       public $compid = null;
       public $JTJavaScript1 = null;
       public $cmbcompletion = null;
       public $Label3 = null;
       public $cmbType = null;
       public $lblType = null;
       public $edDesc = null;
       public $edPrice = null;
       public $lblFixedPrice = null;
       public $lblOrby = null;
       public $memoComments = null;
       public $lblComments = null;
       public $cmbVendor = null;
       public $Label2 = null;
       public $Label5 = null;
       public $cmbSchedule = null;
       public $Label1 = null;
       public $Image3 = null;
       public $hiddenReminder = null;
       public $JTSiteTheme1 = null;
       public $hiddenId = null;
       function btnCancelJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       window.close();
       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function Set_Reminder_EditJSLoad($sender, $params)
       {

       ?>
      var track = document.getElementById('cmbSchedule').value;
       var hr = document.getElementById('lblhr_outer');
       var km = document.getElementById('lblHours_outer');
       var dueat = document.getElementById('lblDueat_outer');
       var dueby = document.getElementById('lblDueby_outer');

       //alert(track);
       //alert('www');
       if(track=='Date')
       {
       //alert('date');
       document.getElementById('lblDueby').style.visibility = 'visible';
       document.getElementById('f-calendar-field-1').style.visibility = 'visible';
       document.getElementById('edDue_outer').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-2').style.visibility = 'visible';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'hidden';
       document.getElementById('lblhr').style.visibility = 'hidden';
       document.getElementById('lblHours').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'visible';
       hr.style.left = '280px';
       km.style.left = '280px';
       dueat.style.left = '160px';
       dueby.style.left = '40px';
       }

       if(track=='Mileage')
       {
       //alert('mileage');
       document.getElementById('lblDueby').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-1').style.visibility = 'hidden';
       document.getElementById('edDue_outer').style.visibility = 'visible';
       document.getElementById('f-calendar-field-2').style.visibility = 'hidden';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'visible';
       document.getElementById('lblhr').style.visibility = 'hidden';
       document.getElementById('lblHours').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'hidden';
       hr.style.left = '300px';
       km.style.left = '324px';
       dueat.style.left = '40px';
       dueby.style.left = '160px';
       }

       if(track=='Hours')
       {
       //alert('hours');
       document.getElementById('lblDueby').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-1').style.visibility = 'hidden';
       document.getElementById('edDue_outer').style.visibility = 'visible';
       document.getElementById('f-calendar-field-2').style.visibility = 'hidden';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'visible';
       document.getElementById('lblhr').style.visibility = 'visible';
       document.getElementById('lblHours').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'hidden';
       hr.style.left = '324px';
       km.style.left = '300px';
       dueat.style.left = '40px';
       dueby.style.left = '160px';
       }


       <?php

       }

       function cmbScheduleJSChange($sender, $params)
       {

       ?>
       var track = document.getElementById('cmbSchedule').value;
       var hr = document.getElementById('lblhr_outer');
       var km = document.getElementById('lblHours_outer');
       var dueat = document.getElementById('lblDueat_outer');
       var dueby = document.getElementById('lblDueby_outer');

       //alert(track);
       //alert('www');
       if(track=='Date')
       {
       //alert('date');
       document.getElementById('lblDueby').style.visibility = 'visible';
       document.getElementById('f-calendar-field-1').style.visibility = 'visible';
       document.getElementById('edDue_outer').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-2').style.visibility = 'visible';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'hidden';
       document.getElementById('lblhr').style.visibility = 'hidden';
       document.getElementById('lblHours').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'visible';
       hr.style.left = '280px';
       km.style.left = '280px';
       dueat.style.left = '160px';
       dueby.style.left = '40px';
       }

       if(track=='Mileage')
       {
       //alert('mileage');
       document.getElementById('lblDueby').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-1').style.visibility = 'hidden';
       document.getElementById('edDue_outer').style.visibility = 'visible';
       document.getElementById('f-calendar-field-2').style.visibility = 'hidden';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'visible';
       document.getElementById('lblhr').style.visibility = 'hidden';
       document.getElementById('lblHours').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'hidden';
       hr.style.left = '280px';
       km.style.left = '324px';
       dueat.style.left = '40px';
       dueby.style.left = '160px';
       }

       if(track=='Hours')
       {
       //alert('hours');
       document.getElementById('lblDueby').style.visibility = 'hidden';
       document.getElementById('f-calendar-field-1').style.visibility = 'hidden';
       document.getElementById('edDue_outer').style.visibility = 'visible';
       document.getElementById('f-calendar-field-2').style.visibility = 'hidden';
       document.getElementById('lblOrby').style.visibility = 'hidden';
       document.getElementById('lblDueat').style.visibility = 'visible';
       document.getElementById('lblhr').style.visibility = 'visible';
       document.getElementById('lblHours').style.visibility = 'visible';
       document.getElementById('f-calendar-trigger-2').style.visibility = 'hidden';
       document.getElementById('f-calendar-trigger-1').style.visibility = 'hidden';
       hr.style.left = '324px';
       km.style.left = '280px';
       dueat.style.left = '40px';
       dueby.style.left = '160px';
       }


       <?php

       }


       function btnDelTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var TypeIndex = document.getElementById('listType').selectedIndex;
       var TypeValue = document.getElementById('listType')[TypeIndex].value;
       var compider3 = document.getElementById('compid').value;
       AjaxType3(TypeValue,compider3);
       <?php

       }

       function btnAddTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       var addtype = document.getElementById('edType').value;
       var compider = document.getElementById('compid').value;
       AjaxType2(addtype,compider);
       document.Reminder_Edit.edType.value = " "
       <?php

       }

       function btnShowTypeJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivType').Show();
       <?php

       }

       function cmbcompletionJSChange($sender, $params)
       {
       echo $this->cmbcompletion->ajaxCall('CompletionChange');
       ?>
       //Add your javascript code here
       return false;
       <?php

       }


       function cmbScheduleChange($sender, $params)
       {
       $schedule = $this->cmbSchedule->getItemIndex();

       if($schedule=='Date')
       {
       $this->lblDueby->Visible=true;
       $this->dpDue1->Visible=true;
       $this->lblHours->Visible=false;
       $this->edDue->Visible=false;
       $this->dpDue2->Visible=false;
       $this->lblOrby->Visible=false;
       $this->lblDueat->Visible=false;
       }
       else if ($schedule=='Both')
       {
       $this->lblDueat->Visible=true;
       $this->edDue->Visible=true;
       $this->dpDue2->Visible=true;
       $this->lblOrby->Visible=true;
       $this->lblDueby->Visible=false;
       $this->dpDue1->Visible=false;
       $this->lblHours->Visible=true;
       }
       else if ($schedule=='Hours/Km')
       {
       $this->dpDue2->Visible=false;
       $this->lblOrby->Visible=false;
       $this->lblDueby->Visible=false;
       $this->dpDue1->Visible=false;
       $this->edDue->Visible=true;
       $this->lblDueat->Visible=true;
       $this->lblHours->Visible=true;
       }


       }


       function CompletionChange()
       {
       $completion = $this->cmbcompletion->getItemIndex();

       if($completion=="WorkOrder")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' and category='type'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }
       }

       if($completion=="Payment")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' and category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }
       }

       if($completion=="None")
       {
        $this->cmbType->Clear();
        $result_type = mysql_query("select * from lookup_expense_tbl where company_id='".$_SESSION['company_id']."' and category='types'");

          while($row_type = mysql_fetch_array($result_type))
          {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
          }
       }


       }



       function Set_Reminder_EditCreate($sender, $params)
       {
       $this->compid->Value = $_SESSION['company_id'];
       $veh_id = $_GET['veh'];
       $this->hiddenId->setValue($veh_id);
       $reminder_id = $_GET['reminder'];
       $this->hiddenReminder->setValue($reminder_id);

       $this->imgBack->setLink('veh_reminder_list.php?veh='.$this->hiddenId->getValue());


       //list type
       $this->listType->Clear();
       $result_t = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' AND category='type'");

        while($row_t = mysql_fetch_array($result_t))
        {
            $this->listType->AddItem($row_t['value'], null, $row_t['value']);
        }
       /*$this->cmbDesc->Clear();
       $result_desc = mysql_query("select * from lookup_workorder_tbl where category='task descriptions'");

        while($row_desc = mysql_fetch_array($result_desc))
        {
            $this->cmbDesc->AddItem($row_desc['value'], null, $row_desc['value']);
        }*/



       $query_reminder = "select * from veh_reminder_tbl where vehicle_id='".$this->hiddenId->getValue()."' and reminder_id='".$this->hiddenReminder->getValue()."'";
       $result_reminder_show = mysql_query($query_reminder)or die("SELECT REMINDER - " . mysql_error());
       $row_reminder = mysql_fetch_array($result_reminder_show);

       $sched_by = $row_reminder['schedule_by'];
       $this->hfsched->setValue($sched_by);

       $this->cmbVendor->AddItem('--Select--', null, null);
       $this->cmbVendor->ItemIndex = $row_reminder['vendor'];
       $result_vendor = mysql_query("select vendor_name from vendor_tbl where company_id='".$_SESSION['company_id']."'");

        while($row_vendor = mysql_fetch_array($result_vendor))
        {
            $this->cmbVendor->AddItem($row_vendor['vendor_name'], null, $row_vendor['vendor_name']);
        }

        $this->cmbType->ItemIndex = $row_reminder['type'];
        $result_type = mysql_query("select * from lookup_workorder_tbl where company_id='".$_SESSION['company_id']."' AND category='type'");

        while($row_type = mysql_fetch_array($result_type))
        {
            $this->cmbType->AddItem($row_type['value'], null, $row_type['value']);
        }


       $result_veh = mysql_query("select * from vehicle_tbl where vehicle_id='".$this->hiddenId->getValue()."'");
       $row_veh = mysql_fetch_array($result_veh);
       $track = $row_veh['track_by'];

       if($track=='distance')
       {
       $this->cmbSchedule->AddItem('Mileage', null, 'Mileage');
       $this->cmbSchedule->ItemIndex = $sched_by;
       }

       if($track=='hours')
       {
       $this->cmbSchedule->AddItem('Hours', null, 'Hours');
       $this->cmbSchedule->ItemIndex = $sched_by;
       }
       //$this->cmbSchedule->AddItem('Mileage', null, 'Mileage');
       //$this->cmbSchedule->AddItem('Hours', null, 'Hours');


       $this->edDue->Text=$row_reminder['due_hours'];
       $this->dpDue1->Text=$row_reminder['due_date'];
       $this->dpDue2->Text=$row_reminder['due_date'];

       /*$sched = $this->cmbSchedule->ItemIndex=$row_reminder['schedule_by'];
       if($sched=='Hours')
       {
       $this->dpDue2->Visible=false;
       $this->lblOrby->Visible=false;
       $this->lblDueby->Visible=false;
       $this->dpDue1->Visible=false;
       $this->edDue->Text=$row_reminder['due_hours'];
       $this->lblDueat->Visible=true;
       $this->lblHours->Visible=true;
       }
       else if($sched=='Date')
       {
       $this->lblDueby->Visible=true;
       $this->dpDue1->Visible=true;
       $this->dpDue1->Text=$row_reminder['due_date'];
       $this->lblHours->Visible=false;
       $this->edDue->Visible=false;
       $this->dpDue2->Visible=false;
       $this->lblOrby->Visible=false;
       $this->lblDueat->Visible=false;
       }
       else
       {
       $this->lblDueat->Visible=true;
       $this->edDue->Visible=true;
       $this->edDue->Text=$row_reminder['due_hours'];
       $this->dpDue2->Visible=true;
       $this->dpDue2->Text=$row_reminder['due_date'];
       $this->lblOrby->Visible=true;
       $this->lblDueby->Visible=false;
       $this->dpDue1->Visible=false;
       $this->lblHours->Visible=true;
       }*/

       //$this->edPrice->Text = $row_reminder['price'];
       $this->memoComments->Text = $row_reminder['comments'];
       $this->cmbcompletion->setItemIndex($row_reminder['completion_window']);
       $this->edDesc->Text = $row_reminder['description'];
       $this->cmbType->setItemIndex($row_reminder['type']);
       }

       function btnCancelClick($sender, $params)
       {
       redirect('set_veh_reminder_list.php?veh='.$this->hiddenId->getValue());


       }

       function btnUpdateClick($sender, $params)
       {
       $hours_save = null;
       $date_save = null;
       if($this->cmbSchedule->getItemIndex()=='Date')
       {
       $date_save = $this->dpDue1->getText();
       }
       if($this->cmbSchedule->getItemIndex()=='Hours' || $this->cmbSchedule->getItemIndex()=='Mileage')
       {
       $hours_save = $this->edDue->Text;
       }
       if($this->cmbSchedule->getItemIndex()=='Both')
       {
       $hours_save = $this->edDue->Text;
       $date_save = $this->dpDue2->getText();
       }


       mysql_query("update veh_reminder_tbl set
       schedule_by = '".$this->cmbSchedule->getItemIndex()."',
       due_hours = '".$hours_save."',
       due_date = '".$date_save."',
       completion_window = '".$this->cmbcompletion->getItemIndex()."',
       type = '".$this->cmbType->getItemIndex()."',
       description = '".$this->edDesc->Text."',
       vendor = '".$this->cmbVendor->getItemIndex()."',
       comments = '".$this->memoComments->Text."'
       where vehicle_id ='".$this->hiddenId->getValue()."' and reminder_id = '".$this->hiddenReminder->getValue()."'")or die ("UPDATE VEHICLE REMINDER-".mysql_error());

       echo "<script type=text/javascript>
        alert('Successfully updated record');
        window.opener.location.reload();
        //window.location.href='set_veh_reminder_create.php';
        window.close();
        </script>";
       //redirect('veh_reminder_list.php?veh='.$this->hiddenId->getValue());
       }

}

global $application;

global $Set_Reminder_Edit;

//Creates the form
$Set_Reminder_Edit=new Set_Reminder_Edit($application);

//Read from resource file
$Set_Reminder_Edit->loadResource(__FILE__);

//Shows the form
$Set_Reminder_Edit->show();

?>